<?php

class Model_Hr_Overbudgetlog extends Zend_Db_Table_Abstract {

	protected $_name = 'shop_overbudget_log';
	
	public function getOverbudgetlog( $idOverbudget){
		
		$row = $this->fetchRow("`id_overbudget` = ". $idOverbudget);
		if(!$row) return false;
		return $row->toArray();		
		
		}
		
	public function addOverbudgetlog( $shop , $dateBegin , $dateEnd , $reason , $applyDate , $applyTime , $approveResult , $approvedBy , $approveDate , $approveTime ,$hourNormal , $hourTrainee){
		
		$data = array(
			
         "shop" =>  $shop ,
         "date_begin" =>  $dateBegin ,
         "date_end" =>  $dateEnd ,
         "reason" =>  $reason ,
         "apply_date" =>  $applyDate ,
         "apply_time" =>  $applyTime ,
         "approve_result" =>  $approveResult ,
         "approved_by" =>  $approvedBy ,
         "approve_date" =>  $approveDate ,
         "approve_time" =>  $approveTime ,
		 "hour_normal" => $hourNormal,
		 "hour_trainee" => $hourTrainee				
			);
		$this->insert($data);
		
		}
		
		public function initOverbudgetlog( $shop , $dateBegin , $dateEnd , $reason , $applyDate , $applyTime , $approveResult , $hourNormal , $hourTrainee){
		
			$data = array(
						
					"shop" =>  $shop ,
					"date_begin" =>  $dateBegin ,
					"date_end" =>  $dateEnd ,
					"reason" =>  $reason ,
					"apply_date" =>  $applyDate ,
					"apply_time" =>  $applyTime ,
					"approve_result" =>  $approveResult,
					"hour_normal" => $hourNormal,
					"hour_trainee" => $hourTrainee
			);
			$this->insert($data);
		
		}	
		
	public function updateOverbudgetlog(  $idOverbudget ,  $shop , $dateBegin , $dateEnd , $reason , $applyDate , $applyTime , $approveResult , $approvedBy , $approveDate , $approveTime){
		$data = array(
			
         "shop" =>  $shop ,
         "date_begin" =>  $dateBegin ,
         "date_end" =>  $dateEnd ,
         "reason" =>  $reason ,
         "apply_date" =>  $applyDate ,
         "apply_time" =>  $applyTime ,
         "approve_result" =>  $approveResult ,
         "approved_by" =>  $approvedBy ,
         "approve_date" =>  $approveDate ,
         "approve_time" =>  $approveTime 
	
			);
			
		$this->update($data,"`id_overbudget` = ". $idOverbudget);
		
	}
		
		public function updateStatus(  $idOverbudget , $approveResult , $approvedBy , $approveDate , $approveTime){
			$data = array(
					"approve_result" =>  $approveResult ,
					"approved_by" =>  $approvedBy ,
					"approve_date" =>  $approveDate ,
					"approve_time" =>  $approveTime
			);
			$this->update($data,"`id_overbudget` = ". $idOverbudget);
		}		
		
	public function deleteOverbudgetlog( $idOverbudget){
		
		$this->delete("`id_overbudget` = ". $idOverbudget);
		
		}	
	
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_overbudget DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}	
	/**
	 * 
	 * I only get the first Row , if the shop applied twice and simon still did not approval the first time
	 * the status will change but only for the late row 
	 * @param unknown_type $shop
	 * @param unknown_type $dateBegin
	 * @param unknown_type $dateEnd
	 */		
		
	public function getByShop($shop,$dateBegin,$dateEnd){
		$whereStr = "`shop` LIKE '{$shop}' AND `date_begin` = '{$dateBegin}' AND `date_end` = '{$dateEnd}'";
		$row = $this->fetchRow($whereStr,"id_overbudget DESC ");
		if(!$row) return false;
		return $row->toArray();
	}	
	
}

?>